$(document).ready(function() {
	$("#pageSelection").bind("change",function(){
		$("#operatorsTable").load(getRootPath()+ "/MainMenu/configuration/operatorList.htm",{pageIndex:$("#pageSelection").val()});
	});
	
	$("#previousButton").bind("click",function(){
		$("#operatorsTable").load(getRootPath()+ "/MainMenu/configuration/operatorList.htm",{pageIndex:$("#previousPageIndex").val()});
	});
	
	$("#nextButton").bind("click",function(){
		$("#operatorsTable").load(getRootPath()+ "/MainMenu/configuration/operatorList.htm",{pageIndex:$("#nextPageIndex").val()});
	});
	
	$( "#progressbar" ).dialog({
		autoOpen:false,
		width:100,
		height:50,
		modal:true
	});

});

function edit(id) {
	$.getJSON(getRootPath()+ "/MainMenu/configuration/editOperator.htm",{operatorID:id}, function(json){
		  $("#name").val(json.operator.name);
		  $("#userName").val(json.operator.userName);
		  $("#operatorID").val(json.operator.id);
		  $.each( json.operator.permissions, function(index, permission){
			 	$("input[type=checkbox][value='"+permission.permissionID+"']").attr("checked","checked");
			});
		  //data load complete, open the dialog
		  $("#addOperatorFormDiv").dialog("open");
		});
}

function deleteOperator(id){
	$( "#progressbar" ).dialog("open");
	$.getJSON(getRootPath()+ "/MainMenu/configuration/deleteOperator.htm",{operatorID:id}, function(json){
		if(json.error==undefined){
			alert("删除成功");
			$("#operatorsTable").load(getRootPath()+ "/MainMenu/configuration/operatorList.htm",{pageIndex:$("#currentPageIndex").val()});
		}else{
			alert("删除失败");
		}
	});
}